import React, { useState, useEffect } from 'react';
import './index.less';

interface IProps {
  defaultValue?: string;
  value?: string;
  onChange?: () => void;
  options?: any[];
}
export default function SearchInput(props: IProps) {
  const { defaultValue, value, onChange, options } = props;
  const [currentValue, setCurrentValue] = useState<
    string | undefined | number | readonly string[]
  >(defaultValue || value || '');

  const [bool] = useState(Object.prototype.hasOwnProperty.call(props, 'value')); //验证是否有传递过来的值

  return (
    <div>
      <input
        value={bool ? value : currentValue} //如果有传递下来的值绑定传递的
        onChange={(e) => {
          const newValue = e.target.value.trim(); //获取新值

          onChange && onChange(newValue); //调用传递过来的值
          setCurrentValue(newValue);
        }}
      />
      <input
        type="file"
        onChange={(e) => {
          console.log(e.target);
        }}
      />
    </div>
  );
}
